package org.apache.commons.graph.algorithms.elo

import org.apache.commons.graph.CommonsGraph.eloRate
import org.apache.commons.graph.CommonsGraph.newDirectedMutableGraph
import org.apache.commons.graph.DirectedGraph
import org.apache.commons.graph.builder.AbstractGraphConnection
import org.junit.Test

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/**
 * Sample taken from [teamliquid](http://www.teamliquid.net/forum/viewmessage.php?topic_id=253017)
 */
class EloTestCase {
    @Test
    fun testPerformElo() {
        val tournament: DirectedGraph<String, GameResult> =
            newDirectedMutableGraph(object : AbstractGraphConnection<String, GameResult>() {
                override fun connect() {
                    val zenio = addVertex("Zenio")
                    val marineking = addVertex("Marineking")
                    val hongun = addVertex("Hongun")
                    val nestea = addVertex("Nestea")
                    val tester = addVertex("Tester")
                    val nada = addVertex("Nada")
                    val rainbow = addVertex("Rainbow")
                    val thewind = addVertex("Thewind")
                    val inka = addVertex("Inka")
                    val maka = addVertex("Maka")
                    val ensnare = addVertex("Ensnare")
                    val kyrix = addVertex("Kyrix")
                    val killer = addVertex("Killer")
                    val slayersboxer = addVertex("Slayersboxer")
                    val fruitdealer = addVertex("Fruitdealer")
                    val genius = addVertex("Genius")

                    // no draws
                    addEdge(GameResult.WIN).from(zenio).to(marineking)
                    addEdge(GameResult.WIN).from(fruitdealer).to(hongun)
                    addEdge(GameResult.WIN).from(genius).to(nestea)
                    addEdge(GameResult.WIN).from(tester).to(nada)
                    addEdge(GameResult.WIN).from(thewind).to(rainbow)
                    addEdge(GameResult.WIN).from(maka).to(inka)
                    addEdge(GameResult.WIN).from(kyrix).to(ensnare)
                    addEdge(GameResult.WIN).from(slayersboxer).to(killer)
                    addEdge(GameResult.WIN).from(marineking).to(fruitdealer)
                    addEdge(GameResult.WIN).from(tester).to(genius)
                    addEdge(GameResult.WIN).from(thewind).to(maka)
                    addEdge(GameResult.WIN).from(kyrix).to(slayersboxer)
                    addEdge(GameResult.WIN).from(marineking).to(tester)
                    addEdge(GameResult.WIN).from(kyrix).to(thewind)
                    addEdge(GameResult.WIN).from(kyrix).to(marineking)
                }
            })

        val playersRank: PlayersRank<String> =
            org.apache.commons.graph.algorithms.elo.SimplePlayersRank()

        eloRate(tournament).wherePlayersAreRankedIn(playersRank).withKFactor(80)

        println(playersRank)
    }
}
